var fetch5 = function(pageIndex ,callback){
  pageIndex = pageIndex || 1
  //更换房客频繁 frequentReplacementOfTenantsTable
  $.ajax({
    type: 'GET',
    url: houseInfo.ajaxUrl[4].page(pageIndex,10),
    beforeSend: function (xhr) {
      xhr.setRequestHeader('Authorization', tokenPgAuth);
      xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
    }
  }).done(function (response) {
    var options = {
      bDestroy:true,
      searching: false,
      bPaginate: false ,//表格分页
      bSort: false,
      bLengthMenu: false,
      bInfo: false,
      pageLength:10, // 每页显示数量
      bAutoWidth: false,
      bLengthChange: false,
      bProcessing: true,
      data: response,
      fnPageChange:function(settings){
        changePage(settings,'.frequentReplacementOfTenantsTable',1)
      },
        columns: [
          {
            data: "simpleaddr",
            className: 'address',
            bSortable: false,
            align: 'left',
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: "housenumber",
            class: 'digit ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: 'stats_per_lock_for_formal_last_15day',
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return ~~data.granted_keys
            }
          },
          {
            data: 'stats_per_lock_for_formal_last_15day',
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return ~~data.tally_revoked_keys
              //return full.stats_per_lock_for_formal_last_15day ? full.stats_per_lock_for_formal_last_15day.tally_user_sessions: '--'
            }
          },
          {
            data: 'stats_per_lock_for_formal_last_15day', //钥匙有效期
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return ~~data.tally_user_sessions
              //return full.stats_per_lock_for_formal_last_15day ? full.stats_per_lock_for_formal_last_15day.tally_user_sessions: '--'
            }
          },
        ]
    };
    options.fnInitComplete =  function (settings) {
      $.ajax({
        type: 'GET',
        url: houseInfo.ajaxUrlTotal[4].page(1,1),
        beforeSend: function (xhr) {
          xhr.setRequestHeader('Authorization', tokenPgAuth);
          xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
          xhr.setRequestHeader('Prefer', 'count=exact');
        }
      }).done(function (res,type,request1) {
        settings.oFeatures.bPaginate = true;
        houseInfo.total[4] = pgApiUtils.getTotal(request1); // 一房多人的总数
        $('.' + houseInfo.totalDomId[4] + 1).text(houseInfo.total[4])
        $('#' + houseInfo.totalDomId[4] + 2).text(houseInfo.total[4])
        settings._pgAiDisplayLength =  houseInfo.total[4]
        settings.oFeatures.bProcessing = false
        settings.oApi._fnAddOptionsHtml(settings)
        settings.oApi._fnDraw(settings)

        var myOptions = jQuery.extend(options, {
          fnPageChange : function(settings){
            changePage(settings,'.frequentReplacementOfTenantsTable',0)
          },
          fnInitComplete : function(settings){
            settings.oFeatures.bPaginate = true;
            settings._pgAiDisplayLength = houseInfo.total[4]
            settings.oFeatures.bProcessing = false
            settings.oApi._fnAddOptionsHtml(settings)
            settings.oApi._fnDraw(settings)
            houseInfo.bindEvent[4]()
          }
        });
        houseInfo.tables[4][1] = $('.frequentReplacementOfTenantsTable').eq(1).dataTable(myOptions);

        if(typeof(callback) === 'function') {
          callback()
        }
      })

    }

    houseInfo.tables[4][0] = $('.frequentReplacementOfTenantsTable').eq(0).dataTable(options);

  })
}



houseInfo.bindEvent[4] = function () {
  $(".frequentReplacementOfTenantsTable").each(function (index,item){
    $(item).on("click","td.address",function(){//给tr或者td添加click事件
      var trDom = $(this)[0]
      var data=houseInfo.tables[4][index].api().row(trDom).data();//获取值的对象数据
      console.log(data);
      getRenterListAndHouseMaster(data)
    })
    $(item).on("click","td.ta",function(){//给tr或者td添加click事件
      var trDom = $(this)[0]
      var data=houseInfo.tables[4][index].api().row(trDom).data();//获取值的对象数据
      KeysIssuedDuringTheCycle(data)
    })
  })
}
